package edu.serg.mbar.algorithms.functions;

import java.text.SimpleDateFormat;
import java.util.Vector;
import java.util.Calendar;
import java.util.Date;

import org.apache.log4j.Logger;

import edu.serg.mbar.ucon.interfaces.IFunction;

/**
 * This class is for retrieving the values of environment variables
 * 
 * @author Sanaullah
 *
 */
public class EnvironmentVariable implements IFunction {
	static Logger log = Logger.getLogger(EnvironmentVariable.class);
	
	@Override
	/**
	 * this Function is used to retrieve the values of different environment variables
	 * 
	 * @param
	 * 	The Vector of Objects the first element of this vector is the name of the environment variable whose value is to be retrieved
	 * 
	 */
	public Object evaluate(Vector<Object> param) {
		log.debug("Recieved a request to retrieve the value of an environment variable");
		Object value = new Object();
		//the id of the environment variable to be retrieved
		String  variableIdentityKey = (String) param.elementAt(0);		
		log.debug("the name of the environment variable whose value is to be retreived is " + variableIdentityKey);
					
		if (variableIdentityKey.equalsIgnoreCase("CurrentTime")){
			SimpleDateFormat dateFormat = new SimpleDateFormat("HHmm");
			Calendar calendar = Calendar.getInstance();
			log.debug("The Value of the environment variable is " + calendar.getTime().toString());
			Date currentTime=calendar.getTime();
			value =dateFormat.format(currentTime);
//			String stringValue="";
//			value = value.toString();
		}
		
		return value;
	}

}
